<template>
  <div>
    <div class="top-panel__box">
      <el-form :model="dataForm" ref="dataForm" inline size="small" onsubmit="return false">
        <el-form-item>
          <el-input placeholder="输入客户姓名/借款编号" v-model="dataForm.freeCondition" maxlength="30" clearable />
        </el-form-item>
        <el-form-item>
          <el-input placeholder="受理人" v-model="dataForm.acceptorName" maxlength="30" clearable />
        </el-form-item>
        <el-form-item>
          <el-date-picker type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd HH:mm:ss" v-model="dataForm.beginTime" style="width:220px" placeholder="跟进时间起" />
          <span>-</span>
          <el-date-picker type="date" format="yyyy-MM-dd" v-model="dataForm.endTime" value-format="yyyy-MM-dd HH:mm:ss" style="width:220px" placeholder="跟进时间止" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getList(0)">
            <fa-icon class="fa-search" />查询</el-button>
          <el-button type="primary" @click="downloadExl">
            <fa-icon class="fa-download" />导出</el-button>
          <reset-button :dataForm.sync="dataForm" :fixedData="{pageNum: 0, pageSize: 10}" />
        </el-form-item>
      </el-form>
    </div>
    <el-row class="table-top">
      <el-table :data="dataList" :border="true" v-loading="tableLoading" tooltip-effect="light" class="tc-table" size="small">
        <el-table-column type="index" width="55" fixed="left" label="序号"></el-table-column>
        <template v-for="(column, index) in FOLLOW_HEAD_LIST">
          <el-table-column :prop="column.prop" :label="column.label" :key="index" :width="column.width" :show-overflow-tooltip="true" />
        </template>
      </el-table>
      <el-row class="pagination-top">
        <pagination :pageNum.sync="dataForm.pageNum" :curSizes.sync="dataForm.pageSize" :total="total" @getList="getList" />
      </el-row>
    </el-row>
  </div>
</template>

<script>
import api from '../api'
import { CONSTANT_OBJ } from '@/utils/constant'
import { FOLLOW_HEAD_LIST } from '../js/contant.js'
import {
  exportExcel,
  disposePhone,
  encryptName
} from '@/utils/util'
import { mapState } from 'vuex'
export default {
  data () {
    return {
      FOLLOW_HEAD_LIST,
      tableLoading: false,
      dataForm: {
        freeCondition: '',
        acceptorName: '',
        beginTime: '',
        endTime: '',
        pageNum: 0,
        pageSize: 10
      },
      dataList: [],
      total: 0
    }
  },
  mounted () {
    this.getList()
  },
  methods: {
    // 查询列表
    getList (val) {
      this.dataForm.pageNum = val || this.dataForm.pageNum
      this.tableLoading = true
      api.postQueryFollowData(this.dataForm).then(res => {
        const { responseCode, data } = res
        if (responseCode === CONSTANT_OBJ.RES_SUCCESS) {
          // this.dataList = [{}]
          data.list.forEach(ele => {
            ele.newRes = this.dicts['overdue_follow_result'].childMap[ele.followResult]
            ele.newName = encryptName(ele.customerName)
            ele.newAddr = ele.organCity ? `${ele.organCity}-${ele.organTown}` : ''
            ele.newProduct = this.dicts['product_type'].childMap[ele.productType]
            ele.newPhone = disposePhone(ele.callPhone)
          })
          this.dataList = data.list || []
          this.total = parseInt(data.total) || 0
        }
      }).finally(() => {
        this.tableLoading = false
      })
    },
    downloadExl () {
      let parmas = {
        freeCondition: this.dataForm.freeCondition,
        acceptorName: this.dataForm.acceptorName,
        beginTime: this.dataForm.beginTime,
        endTime: this.dataForm.endTime
      }
      let path = `/v1/api/esale-pay/repay/follow/exportExcel`
      let name = '跟进记录'
      exportExcel(path, parmas, name)
    }
  },
  computed: {
    ...mapState({
      dicts: state => state.common.dicts
    })
  }
}
</script>
